package com.tang.mybatis.binding;

import com.tang.mybatis.session.SqlSession;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Tang
 * @classname MapperRegistry
 * @description [  ]
 * @date 2022/4/6 23:46
 */
public class MapperRegistry {

    private final Map<Class<?>, MapperProxyFactory<?>> knownMappers = new HashMap<>();

    public <T> void addMapper(Class<T> clz) {
        knownMappers.put(clz, new MapperProxyFactory<T>(clz));
    }

    public <T> T getMapper(Class<T> clz, SqlSession sqlSession) {
        return knownMappers.get(clz).newInstance(sqlSession);
    }

}